/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.unitedats.HR.Entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.unitedats.common.util.SearchRequired;

/**
 *
 * @author Awad
 */
@Entity
@Table(name = "hr_department")
@XmlRootElement
@NamedQueries({
		@NamedQuery(name = "HrDepartment.findAll", query = "SELECT h FROM HrDepartment h"),
		@NamedQuery(name = "HrDepartment.findById", query = "SELECT h FROM HrDepartment h WHERE h.id = :id"),
		@NamedQuery(name = "HrDepartment.findByName", query = "SELECT h FROM HrDepartment h WHERE h.name = :name"),
		@NamedQuery(name = "HrDepartment.findByLevel", query = "SELECT h FROM HrDepartment h WHERE h.level = :level"),
		@NamedQuery(name = "HrDepartment.findByPath", query = "SELECT h FROM HrDepartment h WHERE h.path = :path"),
		@NamedQuery(name = "HrDepartment.findByStatus", query = "SELECT h FROM HrDepartment h WHERE h.status = :status"),
		@NamedQuery(name = "HrDepartment.findRoot", query = "SELECT h FROM HrDepartment h WHERE h.id = h.parentId.id ") })
public class HrDepartment implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Integer id;

	@Column(name = "name")
	private String name;

	@Column(name = "description")
	private String description;

	@SearchRequired
	@Column(name = "level")
	private Integer level;

	@Column(name = "path")
	private String path;

	@Column(name = "created_in")
	@Temporal(TemporalType.TIMESTAMP)
	private Date createdIn;

	@Column(name = "last_modified_in")
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastModifiedIn;

	@SearchRequired
	@Column(name = "status")
	private Boolean status;
	@JoinColumn(name = "last_modified_by", referencedColumnName = "id")
	@ManyToOne
	private HrEmployee lastModifiedBy;
	@JoinColumn(name = "created_by", referencedColumnName = "id")
	@ManyToOne
	private HrEmployee createdBy;
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parentId")
	private List<HrDepartment> hrDepartmentList;
	@SearchRequired
	@JoinColumn(name = "parent_id", referencedColumnName = "id")
	@ManyToOne(fetch = FetchType.LAZY)
	private HrDepartment parentId;

	public HrDepartment() {
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Date getCreatedIn() {
		return createdIn;
	}

	public void setCreatedIn(Date createdIn) {
		this.createdIn = createdIn;
	}

	public Date getLastModifiedIn() {
		return lastModifiedIn;
	}

	public void setLastModifiedIn(Date lastModifiedIn) {
		this.lastModifiedIn = lastModifiedIn;
	}

	public Boolean getStatus() {
		return status;
	}

	public void setStatus(Boolean status) {
		this.status = status;
	}

	public HrEmployee getLastModifiedBy() {
		return lastModifiedBy;
	}

	public void setLastModifiedBy(HrEmployee lastModifiedBy) {
		this.lastModifiedBy = lastModifiedBy;
	}

	public HrEmployee getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(HrEmployee createdBy) {
		this.createdBy = createdBy;
	}

	@XmlTransient
	public List<HrDepartment> getHrDepartmentList() {
		return hrDepartmentList;
	}

	public void setHrDepartmentList(List<HrDepartment> hrDepartmentList) {
		this.hrDepartmentList = hrDepartmentList;
	}

	public HrDepartment getParentId() {
		return parentId;
	}

	public void setParentId(HrDepartment parentId) {
		this.parentId = parentId;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof HrDepartment)) {
			return false;
		}
		HrDepartment other = (HrDepartment) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "com.unitedats.HR.Entity.HrDepartment[ id=" + id + " ]";
	}

}
